﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.ComponentModel;
using System.Windows.Controls;
using GameLogic.Controls;

namespace Bubbles
{
    public partial class BubblesGame : UserControl, IGameFeatures
    {
        public BubblesGame()
        {
            InitializeComponent();

            _playground.GameFinished += (s,e) =>
                {
                    if (GameOverFired != null)
                    {
                        GameOverFired(this, EventArgs.Empty);
                    }
                };

            _playground.BubblesRemoved += (s, e) =>
                {
                    FirePoints(e.BubbleCount * e.BubbleCount);
                };
            
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                // Init Trick
                Settings.Level = Settings.Level;
            }
        }

        public void Start()
        {
            _playground.Opacity = 1;
            _playground.Start();
        }

        public void Stop()
        {

        }

        public event EventHandler GameOverFired;

        private void FirePoints(int points)
        {
            if (ChangeScoresFired != null)
            {
                ScoresChangedEventArgs args = new ScoresChangedEventArgs();
                args.Value = points;
                ChangeScoresFired(this, args);
            }
        }

        public event EventHandler<ScoresChangedEventArgs> ChangeScoresFired;
        public event EventHandler<LivesChangedEventArgs> ChangeLivesFired;

        //public void ChangeScores(int points)
        //{

        //}

        //public void ChangeLives(int lives)
        //{

        //}

        public void Pause()
        {

        }

        public void GameOver(GameOverEventArgs args)
        {

        }

        public void Resume()
        {

        }

        //public event EventHandler NewGameFired;

        //public event EventHandler<HighscoreEntryArgs> HighscoreEntryFired;

        public bool IsTimeBased
        {
            get { return false; }
        }

        public bool IsLifeBase
        {
            get { throw new NotImplementedException(); }
        }

        public string GameName
        {
            get { return "Bubbles"; }
        }

        public bool IsLifeBased
        {
            get { return false; }
        }




        public TimeSpan GameDuration
        {
            get { throw new NotImplementedException(); }
        }
    }
}
